package com.zenchn.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zenchn.annotation.OperLog;
import com.zenchn.entity.*;
import com.zenchn.enums.*;
import com.zenchn.exception.CheckException;
import com.zenchn.exception.CustomException;
import com.zenchn.external.service.FileGenericStrategy;
import com.zenchn.model.*;
import com.zenchn.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 医院信息管理控制器
 *
 * @author panbingqi
 * @date 2021-06-04 17:34
 */
@RestController
@RequestMapping(value = "hospitalManageWeb")
@Api(value = "医院信息管理模块相关接口", tags = "信息管理-医院信息管理")
@RequiresPermissions("information:manage:hospital")
public class HospitalManageWebController {
    private final String MODULE = "信息管理>医院信息管理";

    @Resource
    private RegionService regionService;

    @Resource
    private RegionDetailService regionDetailService;

    @Resource
    private CustomerContactsService customerContactsService;

    @Resource
    private CustomerVisitService customerVisitService;

    @Resource
    private CustomerService customerService;

    @Resource
    private FileGenericStrategy fileGenericStrategy;

    @Resource
    private AreasService areasService;

    @Resource
    private DictService dictService;

    @Resource
    private CustomerUpgradeService customerUpgradeService;

    @Resource
    private AccountService accountService;

    @Resource
    private CustomerTransferService customerTransferService;


    /**
     * 分页获取医院信息管理列表
     *
     * @param keyword
     * @param regionId
     * @param areasCode
     * @param accountId
     * @param level
     * @param isOvertime
     * @param startTime
     * @param endTime
     * @param page
     * @param pageSize
     * @param request
     * @param response
     * @return
     */
    @OperLog(module = MODULE, action = OperLogActionEnum.QUERY, detail = "分页获取医院信息管理列表")
    @ApiOperation(value = "分页获取医院信息管理列表", notes = "分页获取医院信息管理列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "keyword", value = "关键字"),
            @ApiImplicitParam(dataType = "String", name = "regionId", value = "所属大区"),
            @ApiImplicitParam(dataType = "String", name = "areasCode", value = "所属省份"),
            @ApiImplicitParam(dataType = "String", name = "accountId", value = "所属用户"),
            @ApiImplicitParam(dataType = "Integer", name = "level", value = "等级"),
            @ApiImplicitParam(dataType = "Boolean", name = "isOvertime", value = "超时未升级"),
            @ApiImplicitParam(dataType = "Date", name = "startTime", value = "参数名称，开始时间", required = true),
            @ApiImplicitParam(dataType = "Date", name = "endTime", value = "参数名称，结束时间", required = true),
            @ApiImplicitParam(dataType = "Integer", name = "page", value = "当前第page页"),
            @ApiImplicitParam(dataType = "Integer", name = "pageSize", value = "每页pageSize数量")
    })
    @GetMapping(value = "/list")
    @RequiresPermissions("information:manage:hospital")
    public ResponseEntity<HttpDataResult<PageInfo>> list(
            @RequestParam(required = false, value = "keyword") String keyword,
            @RequestParam(required = false, value = "regionId") String regionId,
            @RequestParam(required = false, value = "areasCode") String areasCode,
            @RequestParam(required = false, value = "accountId") String accountId,
            @RequestParam(required = false, value = "level") Integer level,
            @RequestParam(required = false, value = "isOvertime") Boolean isOvertime,
            @RequestParam(value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
            @RequestParam(value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime,
            @RequestParam(required = false, value = "page", defaultValue = "1") Integer page,
            @RequestParam(required = false, value = "pageSize", defaultValue = "10") Integer pageSize,
            HttpServletRequest request, HttpServletResponse response) throws Exception {

        HttpDataResult<PageInfo> result = new HttpDataResult<>(request.getRequestURI());

        final TMiAccountExtend accountExtend = (TMiAccountExtend) request.getSession().getAttribute(SessionAttributeEnum.CURRENT_ACCOUNT_EXTEND_INFO.getKey());
        if (accountExtend == null) {
            throw new CustomException("当前登入账户无数据权限");
        }
        //获取当前登入用户所属省份数据权限
        List<String> areasCodeList = new ArrayList<>();
        if (accountExtend.getRegionCode() != null && !"".equals(accountExtend.getRegionCode().trim())) {
            areasCodeList = getAreasCodeList(accountExtend.getRegionCode().trim());
        }
        if (accountExtend.getAreasCode() != null && !"".equals(accountExtend.getAreasCode()) && !areasCodeList.contains(accountExtend.getAreasCode())) {
            areasCodeList.add(accountExtend.getAreasCode().trim());
        }
        //取交集
        List<String> resultList = new ArrayList<>();
        if (regionId != null && !"".equals(regionId.trim())) {
            List<String> codeList = getAreasCodeList(regionId);
            for (String code : areasCodeList) {
                if (codeList.contains(code)) {
                    resultList.add(code);
                }
            }
        } else {
            resultList.addAll(areasCodeList);
        }

        if (resultList.isEmpty()) {
            result.setData(new PageInfo());
        } else {
            LocalDateTime startDate = null;
            if (startTime != null) {
                startDate = LocalDateTime.of(startTime, LocalTime.MIN);
            }
            LocalDateTime endDate = null;
            if (endTime != null) {
                endDate = LocalDateTime.of(endTime, LocalTime.MAX);
            }

            PageHelper.startPage(page, pageSize);
            PageInfo pageInfo = new PageInfo(customerService.selectHospitalDynamicSqlByParameter(keyword, resultList, areasCode, accountId, level, startDate, endDate));

            List<TMiCustomer> customerList = pageInfo.getList();
            List<CustomerVO> customerVOList = new ArrayList<>();
            for (TMiCustomer customer : customerList) {
                CustomerVO customerVO = new CustomerVO();
                BeanUtils.copyProperties(customer, customerVO);
                //设置区域名称
                TMiRegionDetailExample regionDetailExample = new TMiRegionDetailExample();
                regionDetailExample.createCriteria().andAreasCodeEqualTo(customer.getAreasCode()).andRegionIdNotEqualTo(RegionEnum.NATIONAL_ADMINISTRATIVE_REGION.getId());

                List<String> regionIdList = regionDetailService.selectByExample(regionDetailExample).stream().map(TMiRegionDetail::getRegionId).collect(Collectors.toList());
                if (regionIdList != null && !regionIdList.isEmpty()) {
                    TMiRegionExample regionExample = new TMiRegionExample();
                    regionExample.createCriteria().andRegionIdIn(regionIdList);

                    customerVO.setRegionName(regionService.selectByExample(regionExample).stream().map(TMiRegion::getRegionName).collect(Collectors.joining(",")));
                }
                //设置省级名称
                TSysAreas areas = areasService.selectByPrimaryKey(customer.getAreasCode());
                if (areas != null) {
                    customerVO.setAreasCodeName(areas.getName());
                }
                //设置默认联系人信息
                TMiCustomerContactsExample customerContactsExample = new TMiCustomerContactsExample();
                customerContactsExample.createCriteria().andCustomerIdEqualTo(customer.getCustomerId()).andIsDefaultEqualTo("1");

                List<TMiCustomerContacts> customerContactsList = customerContactsService.selectByExample(customerContactsExample);
                if (customerContactsList != null && !customerContactsList.isEmpty()) {
                    TMiCustomerContacts customerContacts = customerContactsList.get(0);
                    customerVO.setCustomerContacts(customerContacts);
                }
                //设置代理商信息
                if ("0".equals(customer.getBelongTo())) {
                    customerVO.setBelongToName("总公司");
                } else {
                    TMiCustomer tMiCustomer = customerService.selectByPrimaryKey(customer.getBelongTo());
                    if (tMiCustomer != null) {
                        customerVO.setBelongToName(tMiCustomer.getCustomerName());
                    }
                }
                //设置医院等级
                customerVO.setHospitalLevel(CustomerLevelTypeEnum.getHospitalDesc(customer.getLevel()));
                //设置所属用户名称
                TSysAccount account = accountService.selectByPrimaryKey(customer.getAccountId());
                if (account != null) {
                    customerVO.setAccountName(account.getRealName());
                }

                customerVOList.add(customerVO);
            }

            List<CustomerVO> overTimeList = new ArrayList<>();
            //获取超时时间
            TSysDict dict = dictService.selectByPrimaryKey(HospitalOvertimeEnum.HOSPITAL_OVERTIME.getOvertimeId());
            if (dict != null) {
                for (CustomerVO customerVO : customerVOList) {
                    LocalDateTime start = customerVO.getCreateTime();
                    LocalDateTime end = start.plusDays(Long.valueOf(dict.getDictValue()));
                    if (LocalDateTime.now().isBefore(end) || customerVO.getLevel() != CustomerLevelTypeEnum.ONE.getType()) {
                        continue;
                    }
                    TMiCustomerUpgradeExample customerUpgradeExample = new TMiCustomerUpgradeExample();
                    TMiCustomerUpgradeExample.Criteria criteria = customerUpgradeExample.createCriteria();
                    criteria.andCustomerIdEqualTo(customerVO.getCustomerId());
                    criteria.andIsEnableEqualTo(CustomerStatusEnum.EFFECTIVE.getUpgradeStatus());
                    criteria.andUpgradeTypeEqualTo(UpgradeTypeEnum.UPGRADE_OPERATION.getUpgradeType());
                    criteria.andCreateTimeGreaterThanOrEqualTo(start);
                    criteria.andCreateTimeLessThanOrEqualTo(end);

                    if (customerUpgradeService.countByExample(customerUpgradeExample) <= 0) {
                        customerVO.setUpgrade(true);
                        overTimeList.add(customerVO);
                    }
                }
            }
            if (isOvertime != null && isOvertime) {
                pageInfo.setList(overTimeList);
            } else {
                pageInfo.setList(customerVOList);
            }

            result.setData(pageInfo);
        }

        result.setMessage("分页获取医院信息管理列表成功.");
        result.setStatus(HttpStatus.OK.value());
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    /**
     * 获取省份信息
     *
     * @param regionId
     * @return
     */
    private List<String> getAreasCodeList(String regionId) {
        List<String> areasCodeList = new ArrayList<>();
        TMiRegionDetailExample regionDetailExample = new TMiRegionDetailExample();
        regionDetailExample.createCriteria().andRegionIdEqualTo(regionId);

        List<TMiRegionDetail> regionDetailList = regionDetailService.selectByExample(regionDetailExample);
        if (regionDetailList != null && !regionDetailList.isEmpty()) {
            areasCodeList.addAll(regionDetailList.stream().map(TMiRegionDetail::getAreasCode).collect(Collectors.toList()));
        }
        return areasCodeList;
    }


    /***
     * 医院管理信息详情 （修改页获取数据）
     * @param customerId
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @OperLog(module = MODULE, action = OperLogActionEnum.QUERY, detail = "医院管理信息详情 （修改页获取数据）")
    @ApiOperation(value = "医院管理信息详情 （修改页获取数据）", notes = "医院管理信息详情 （修改页获取数据）")
    @ApiImplicitParam(dataType = "String", name = "customerId", value = "客户ID", required = true)
    @GetMapping(value = "/detail")
    public ResponseEntity<HttpDataResult<Map<String, Object>>> detail(
            @RequestParam(value = "customerId") String customerId,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpDataResult<Map<String, Object>> result = new HttpDataResult<>(request.getRequestURI());
        Map<String, Object> resultData = new HashMap<>(16);

        //获取代理商信息
        TMiCustomer customer = customerService.selectByPrimaryKey(customerId);
        CustomerVO customerVO = new CustomerVO();
        BeanUtils.copyProperties(customer, customerVO);
        //设置省级名称
        TSysAreas areas = areasService.selectByPrimaryKey(customer.getAreasCode());
        if (areas != null) {
            customerVO.setAreasCodeName(areas.getName());
        }
        //设置医院等级
        customerVO.setHospitalLevel(CustomerLevelTypeEnum.getHospitalDesc(customer.getLevel()));
        //设置所属用户名称
        TSysAccount account = accountService.selectByPrimaryKey(customer.getAccountId());
        if (account != null) {
            customerVO.setAccountName(account.getRealName());
        }
        resultData.put("customerVO", customerVO);

        //获取联系人信息
        TMiCustomerContactsExample customerContactsExample = new TMiCustomerContactsExample();
        customerContactsExample.createCriteria().andCustomerIdEqualTo(customerId);

        List<TMiCustomerContacts> customerContactsList = customerContactsService.selectByExample(customerContactsExample);
        resultData.put("customerContactsList", customerContactsList);

        //获取拜访记录信息
        List<CustomerContactsVO> customerContactsVOList = new ArrayList<>();
        TMiCustomerVisitExample customerVisitExample = new TMiCustomerVisitExample();
        customerVisitExample.createCriteria().andCustomerIdEqualTo(customerId);
        customerContactsExample.setOrderByClause("visit_date");

        List<TMiCustomerVisit> customerVisitList = customerVisitService.selectByExample(customerVisitExample);
        Map<String, List<TMiCustomerVisit>> customerVisitMap = new TreeMap<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.compareTo(o1);
            }
        });
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        if (null != customerVisitList && !customerVisitList.isEmpty()) {
            for (TMiCustomerVisit customerVisit : customerVisitList) {
                //获取拜访人名称
                String visitName = "";
                TSysAccount visitAccount = accountService.selectByPrimaryKey(customerVisit.getCreator());
                if (visitAccount != null) {
                    visitName = visitAccount.getRealName();
                }
                String key = customerVisit.getVisitDate().format(formatter) + "--" + visitName;
                List<TMiCustomerVisit> list;
                if (customerVisitMap.containsKey(key)) {
                    list = customerVisitMap.get(key);
                } else {
                    list = new ArrayList<>();
                }
                list.add(customerVisit);
                customerVisitMap.put(key, list);
            }
        }
        if (customerContactsList != null && !customerContactsList.isEmpty()) {
            for (TMiCustomerContacts customerContacts : customerContactsList) {
                CustomerContactsVO customerContactsVO = new CustomerContactsVO();
                BeanUtils.copyProperties(customerContacts, customerContactsVO);
                String contactsId = customerContacts.getContactsId();
                List<CustomerVisitVO> customerVisitVOList = new ArrayList<>();
                customerVisitMap.forEach((key, value) -> {
                    CustomerVisitVO customerVisitVO = new CustomerVisitVO();
                    StringBuilder stringBuilder = new StringBuilder();
                    for (TMiCustomerVisit customerVisit : value) {
                        if (contactsId.equals(customerVisit.getContactsId())) {
                            stringBuilder.append(customerVisit.getContent() + " ");
                        }
                    }
                    customerVisitVO.setOperatorTimeName(key);
                    customerVisitVO.setVisitContent(stringBuilder.toString());
                    customerVisitVOList.add(customerVisitVO);
                });
                customerContactsVO.setCustomerVisitVOList(customerVisitVOList);
                customerContactsVOList.add(customerContactsVO);
            }
        }
        resultData.put("customerVisitVOList", customerContactsVOList);

        //获取升降级日志信息
        TMiCustomerUpgradeExample customerUpgradeExample = new TMiCustomerUpgradeExample();
        customerUpgradeExample.createCriteria().andCustomerIdEqualTo(customerId);
        customerUpgradeExample.setOrderByClause("create_time desc");

        List<TMiCustomerUpgrade> customerUpgradeList = customerUpgradeService.selectByExample(customerUpgradeExample);
        List<CustomerUpgradeVO> customerUpgradeVOList = new ArrayList<>();
        if (customerUpgradeList != null && !customerUpgradeList.isEmpty()) {
            for (TMiCustomerUpgrade customerUpgrade : customerUpgradeList) {
                CustomerUpgradeVO customerUpgradeVO = new CustomerUpgradeVO();
                BeanUtils.copyProperties(customerUpgrade, customerUpgradeVO);
                //设置操作类型名称
                customerUpgradeVO.setUpgradeTypeName(UpgradeTypeEnum.getAppDesc(customerUpgrade.getUpgradeType()));
                //设置是否有效名称
                customerUpgradeVO.setIsEnableName(CustomerStatusEnum.getAppDesc(customerUpgrade.getIsEnable()));
                //设置升降级操作人名称
                TSysAccount sysAccount = accountService.selectByPrimaryKey(customerUpgrade.getCreator());
                if (sysAccount != null) {
                    customerUpgradeVO.setOperatorName(sysAccount.getRealName());
                }

                customerUpgradeVOList.add(customerUpgradeVO);
            }
        }
        //设置客户初始创建数据
        CustomerUpgradeVO customerUpgradeVO = new CustomerUpgradeVO();
        customerUpgradeVO.setUpgradeLevel(1);
        customerUpgradeVO.setUpgradeTypeName(UpgradeTypeEnum.CREATE_OPERATION.getAppDesc());
        customerUpgradeVO.setIsEnableName(CustomerStatusEnum.EFFECTIVE.getAppDesc());
        customerUpgradeVO.setCreateTime(customer.getCreateTime());
        //设置创建人名称
        TSysAccount upgradeAccount = accountService.selectByPrimaryKey(customer.getCreator());
        if (upgradeAccount != null) {
            customerUpgradeVO.setOperatorName(upgradeAccount.getRealName());
        }
        customerUpgradeVOList.add(customerUpgradeVO);

        resultData.put("customerUpgradeVOList", customerUpgradeVOList);

        //获取转移日志信息
        TMiCustomerTransferExample customerTransferExample = new TMiCustomerTransferExample();
        customerTransferExample.createCriteria().andCustomerIdEqualTo(customerId);
        customerTransferExample.setOrderByClause("create_time desc");

        List<TMiCustomerTransfer> customerTransferList = customerTransferService.selectByExample(customerTransferExample);
        List<CustomerTransferVO> customerTransferVOList = new ArrayList<>();
        if (customerTransferList != null && !customerTransferList.isEmpty()) {
            for (TMiCustomerTransfer customerTransfer : customerTransferList) {
                CustomerTransferVO customerTransferVO = new CustomerTransferVO();
                BeanUtils.copyProperties(customerTransfer, customerTransferVO);
                //设置转移前名称
                TSysAccount beforeAccount = accountService.selectByPrimaryKey(customerTransfer.getBeforeAccountId());
                if (beforeAccount != null) {
                    customerTransferVO.setBeforeAccountName(beforeAccount.getRealName());
                }
                //设置转移后名称
                TSysAccount afterAccount = accountService.selectByPrimaryKey(customerTransfer.getAfterAccountId());
                if (afterAccount != null) {
                    customerTransferVO.setAfterAccountName(afterAccount.getRealName());
                }
                //设置是否有效名称
                customerTransferVO.setIsEnableName(CustomerStatusEnum.getAppDesc(customerTransfer.getIsEnable()));
                //设置转移日志操作人名称
                TSysAccount sysAccount = accountService.selectByPrimaryKey(customerTransfer.getCreator());
                if (sysAccount != null) {
                    customerTransferVO.setOperatorName(sysAccount.getRealName());
                }

                customerTransferVOList.add(customerTransferVO);
            }
        }
        resultData.put("customerTransferVOList", customerTransferVOList);

        result.setData(resultData);
        result.setMessage("OK");
        result.setStatus(HttpStatus.OK.value());
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    /**
     * 导出医院信息
     *
     * @param customerId
     * @param request
     * @param response
     * @return
     */
    @OperLog(module = MODULE, action = OperLogActionEnum.QUERY, detail = "导出医院信息")
    @ApiOperation(value = "导出医院信息", notes = "导出医院信息")
    @ApiImplicitParam(dataType = "String", name = "customerId", value = "客户ID", required = true)
    @GetMapping(value = "/export")
    @RequiresPermissions("information:manage:hospital:export")
    public ResponseEntity<HttpDataResult<String>> export(
            @RequestParam(value = "customerId") String customerId,
            HttpServletRequest request, HttpServletResponse response) throws Exception {

        HttpDataResult<String> result = new HttpDataResult<>(request.getRequestURI());

        TMiCustomer customer = customerService.selectByPrimaryKey(customerId);
        if (null == customer) {
            throw new CustomException("未查询到相关医院信息，无法导出！");
        }

        String regionName = "";
        String areasCodeName = "";
        String agentName = "";
        //设置区域名称
        TMiRegionDetailExample regionDetailExample = new TMiRegionDetailExample();
        regionDetailExample.createCriteria().andAreasCodeEqualTo(customer.getAreasCode()).andRegionIdNotEqualTo(RegionEnum.NATIONAL_ADMINISTRATIVE_REGION.getId());

        List<String> regionIdList = regionDetailService.selectByExample(regionDetailExample).stream().map(TMiRegionDetail::getRegionId).collect(Collectors.toList());
        if (regionIdList != null && !regionIdList.isEmpty()) {
            TMiRegionExample regionExample = new TMiRegionExample();
            regionExample.createCriteria().andRegionIdIn(regionIdList);

            regionName = regionService.selectByExample(regionExample).stream().map(TMiRegion::getRegionName).collect(Collectors.joining(","));
        }
        //设置省级名称
        TSysAreas areas = areasService.selectByPrimaryKey(customer.getAreasCode());
        if (areas != null) {
            areasCodeName = areas.getName();
        }
        //设置代理商信息
        if ("0".equals(customer.getBelongTo())) {
            agentName = "总公司";
        } else {
            TMiCustomer tMiCustomer = customerService.selectByPrimaryKey(customer.getBelongTo());
            if (tMiCustomer != null) {
                agentName = tMiCustomer.getCustomerName();
            }
        }


        //获取单个医院的联系人列表
        TMiCustomerContactsExample customerContactsExample = new TMiCustomerContactsExample();
        customerContactsExample.createCriteria().andCustomerIdEqualTo(customerId);

        List<TMiCustomerContacts> customerContactsList = customerContactsService.selectByExample(customerContactsExample);
        if (null == customerContactsList || customerContactsList.isEmpty()) {
            throw new CustomException("未查询到相关医院拜访记录信息，无法导出！");
        }

        //获取单个医院的拜访记录
        TMiCustomerVisitExample customerVisitExample = new TMiCustomerVisitExample();
        customerVisitExample.createCriteria().andCustomerIdEqualTo(customerId);
        customerContactsExample.setOrderByClause("visit_date");

        List<TMiCustomerVisit> customerVisitList = customerVisitService.selectByExample(customerVisitExample);
        Map<String, List<TMiCustomerVisit>> customerVisitMap = new TreeMap<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.compareTo(o1);
            }
        });
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        if (null != customerVisitList && !customerVisitList.isEmpty()) {
            for (TMiCustomerVisit customerVisit : customerVisitList) {
                //获取拜访人名称
                String visitName = "";
                TSysAccount account = accountService.selectByPrimaryKey(customerVisit.getCreator());
                if (account != null) {
                    visitName = account.getRealName();
                }
                String key = customerVisit.getVisitDate().format(formatter) + "--" + visitName;
                List<TMiCustomerVisit> list;
                if (customerVisitMap.containsKey(key)) {
                    list = customerVisitMap.get(key);
                } else {
                    list = new ArrayList<>();
                }
                list.add(customerVisit);
                customerVisitMap.put(key, list);
            }
        }

        //设置导出相关信息
        XSSFWorkbook wb = new XSSFWorkbook();

        XSSFSheet sheet = wb.createSheet(customer.getCustomerName());

        sheet.setColumnWidth(0, (20 * 256));
        sheet.setColumnWidth(1, (20 * 256));
        sheet.setColumnWidth(2, (25 * 256));
        sheet.setColumnWidth(3, (25 * 256));
        for (int i = 0; i < customerVisitMap.size(); i++) {
            sheet.setColumnWidth(i + 4, (50 * 256));
        }

        XSSFRow row = sheet.createRow(0);
        row.setHeightInPoints(28);
        XSSFFont tableTitleFont = wb.createFont();
        tableTitleFont.setFontHeightInPoints((short) 12);
        tableTitleFont.setBold(true);
        XSSFCellStyle tableTitleStyle = wb.createCellStyle();
        tableTitleStyle.setFont(tableTitleFont);
        // 下边框
        tableTitleStyle.setBorderBottom(BorderStyle.THIN);
        // 左边框
        tableTitleStyle.setBorderLeft(BorderStyle.THIN);
        // 右边框
        tableTitleStyle.setBorderRight(BorderStyle.THIN);
        // 上边框
        tableTitleStyle.setBorderTop(BorderStyle.THIN);
        tableTitleStyle.setAlignment(HorizontalAlignment.CENTER);
        tableTitleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        createCell(row, 0, tableTitleStyle, "大区");
        createCell(row, 1, tableTitleStyle, "省份");
        createCell(row, 2, tableTitleStyle, "医院名称");
        createCell(row, 3, tableTitleStyle, customer.getCustomerName());
        createCell(row, 4, tableTitleStyle, " 代理商");
        createCell(row, 5, tableTitleStyle, agentName);
        createCell(row, 6, tableTitleStyle, " 项目医院分级");
        createCell(row, 7, tableTitleStyle, CustomerLevelTypeEnum.getHospitalDesc(customer.getLevel()));

        XSSFRow row0 = sheet.createRow(1);
        row0.setHeightInPoints(28);

        XSSFFont tableHeaderFont = wb.createFont();
        tableHeaderFont.setFontHeightInPoints((short) 12);
        tableHeaderFont.setBold(true);
        XSSFCellStyle tableHeaderStyle = wb.createCellStyle();
        tableHeaderStyle.setFont(tableHeaderFont);
        // 下边框
        tableHeaderStyle.setBorderBottom(BorderStyle.THIN);
        // 左边框
        tableHeaderStyle.setBorderLeft(BorderStyle.THIN);
        // 右边框
        tableHeaderStyle.setBorderRight(BorderStyle.THIN);
        // 上边框
        tableHeaderStyle.setBorderTop(BorderStyle.THIN);
        tableHeaderStyle.setAlignment(HorizontalAlignment.CENTER);
        tableHeaderStyle.setVerticalAlignment(VerticalAlignment.CENTER);

        createCell(row0, 0, tableHeaderStyle, regionName);
        createCell(row0, 1, tableHeaderStyle, areasCodeName);
        createCell(row0, 2, tableHeaderStyle, "部门");
        createCell(row0, 3, tableHeaderStyle, "姓名");
        int index = 4;
        for (String key : customerVisitMap.keySet()) {
            createCell(row0, index, tableHeaderStyle, key);
            index++;
        }

        XSSFFont fontBody = wb.createFont();
        fontBody.setFontHeightInPoints((short) 11);
        XSSFCellStyle styleBody = wb.createCellStyle();
        styleBody.setFont(fontBody);
        // 下边框
        styleBody.setBorderBottom(BorderStyle.THIN);
        // 左边框
        styleBody.setBorderLeft(BorderStyle.THIN);
        // 右边框
        styleBody.setBorderRight(BorderStyle.THIN);
        // 上边框
        styleBody.setBorderTop(BorderStyle.THIN);
        styleBody.setAlignment(HorizontalAlignment.CENTER);
        styleBody.setVerticalAlignment(VerticalAlignment.CENTER);

        for (int i = 0; i < customerContactsList.size(); i++) {
            TMiCustomerContacts customerContacts = customerContactsList.get(i);
            String contactsId = customerContacts.getContactsId();

            XSSFRow trow = sheet.createRow(i + 2);
            trow.setHeightInPoints(24);
            createCell(trow, 0, styleBody, regionName);
            createCell(trow, 1, styleBody, areasCodeName);
            createCell(trow, 2, styleBody, customerContacts.getPost());
            createCell(trow, 3, styleBody, customerContacts.getContactsName());
            AtomicInteger idx = new AtomicInteger(4);
            customerVisitMap.forEach((key, value) -> {
                StringBuilder stringBuilder = new StringBuilder();
                for (TMiCustomerVisit customerVisit : value) {
                    if (contactsId.equals(customerVisit.getContactsId())) {
                        stringBuilder.append(customerVisit.getContent() + " ");
                    }
                }
                createCell(trow, idx.get(), styleBody, stringBuilder.toString());
                idx.getAndIncrement();
            });
        }
        sheet.addMergedRegion(new CellRangeAddress(1, customerContactsList.size() + 1, 0, 0));
        sheet.addMergedRegion(new CellRangeAddress(1, customerContactsList.size() + 1, 1, 1));

        StringBuilder fileName = new StringBuilder();
        fileName.append(customer.getCustomerName());

        fileName.append("_").append(System.currentTimeMillis());

        //创建临时文件
        File excelFile = File.createTempFile(fileName.toString(), ".xlsx");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        wb.write(baos);
        FileCopyUtils.copy(baos.toByteArray(), new FileOutputStream(excelFile));

        //保存到临时OSS上
        JsonResult<String> jsonResult = fileGenericStrategy.simpleFileUploadTempBucket("downloadExport", excelFile, fileName + ".xlsx");

        // 删除临时文件
        excelFile.delete();

        if (!jsonResult.getSuccess()) {
            throw new CustomException(jsonResult.getData().toString());
        }


        result.setData(jsonResult.getData());
        result.setMessage("OK");
        result.setStatus(HttpStatus.OK.value());


        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    /**
     * 批量导出医院信息
     *
     * @param keyword
     * @param regionId
     * @param areasCode
     * @param accountId
     * @param level
     * @param isOvertime
     * @param startTime
     * @param endTime
     * @param request
     * @param response
     * @return
     */
    @OperLog(module = MODULE, action = OperLogActionEnum.QUERY, detail = "批量导出医院信息")
    @ApiOperation(value = "批量导出医院信息", notes = "批量导出医院信息")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "keyword", value = "关键字"),
            @ApiImplicitParam(dataType = "String", name = "regionId", value = "所属大区"),
            @ApiImplicitParam(dataType = "String", name = "areasCode", value = "所属省份"),
            @ApiImplicitParam(dataType = "String", name = "accountId", value = "所属用户"),
            @ApiImplicitParam(dataType = "Integer", name = "level", value = "等级"),
            @ApiImplicitParam(dataType = "Boolean", name = "isOvertime", value = "超时未升级"),
            @ApiImplicitParam(dataType = "Date", name = "startTime", value = "参数名称，开始时间", required = true),
            @ApiImplicitParam(dataType = "Date", name = "endTime", value = "参数名称，结束时间", required = true)
    })
    @GetMapping(value = "/exportBatch")
    @RequiresPermissions("information:manage:hospital:exportBatch")
    public ResponseEntity<HttpDataResult<String>> exportBatch(
            @RequestParam(required = false, value = "keyword") String keyword,
            @RequestParam(required = false, value = "regionId") String regionId,
            @RequestParam(required = false, value = "areasCode") String areasCode,
            @RequestParam(required = false, value = "accountId") String accountId,
            @RequestParam(required = false, value = "level") Integer level,
            @RequestParam(required = false, value = "isOvertime") Boolean isOvertime,
            @RequestParam(value = "startTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
            @RequestParam(value = "endTime") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime,
            HttpServletRequest request, HttpServletResponse response) throws Exception {

        HttpDataResult<String> result = new HttpDataResult<>(request.getRequestURI());

        final TMiAccountExtend accountExtend = (TMiAccountExtend) request.getSession().getAttribute(SessionAttributeEnum.CURRENT_ACCOUNT_EXTEND_INFO.getKey());
        if (accountExtend == null) {
            throw new CustomException("当前登入账户无数据权限");
        }
        //获取当前登入用户所属省份数据权限
        List<String> areasCodeList = new ArrayList<>();
        if (accountExtend.getRegionCode() != null && !"".equals(accountExtend.getRegionCode().trim())) {
            areasCodeList = getAreasCodeList(accountExtend.getRegionCode().trim());
        }
        if (accountExtend.getAreasCode() != null && !"".equals(accountExtend.getAreasCode()) && !areasCodeList.contains(accountExtend.getAreasCode())) {
            areasCodeList.add(accountExtend.getAreasCode().trim());
        }
        //取交集
        List<String> resultList = new ArrayList<>();
        if (regionId != null && !"".equals(regionId.trim())) {
            List<String> codeList = getAreasCodeList(regionId);
            for (String code : areasCodeList) {
                if (codeList.contains(code)) {
                    resultList.add(code);
                }
            }
        } else {
            resultList.addAll(areasCodeList);
        }

        if (resultList.isEmpty()) {
            throw new CustomException("未查询到相关医院信息，无法导出！");
        }

        LocalDateTime startDate = null;
        if (startTime != null) {
            startDate = LocalDateTime.of(startTime, LocalTime.MIN);
        }
        LocalDateTime endDate = null;
        if (endTime != null) {
            endDate = LocalDateTime.of(endTime, LocalTime.MAX);
        }

        PageInfo pageInfo = new PageInfo(customerService.selectHospitalDynamicSqlByParameter(keyword, resultList, areasCode, accountId, level, startDate, endDate));

        List<TMiCustomer> customerList = pageInfo.getList();
        if (null == customerList || customerList.isEmpty()) {
            throw new CustomException("未查询到相关医院信息，无法导出！");
        }

        if (isOvertime != null && isOvertime) {
            List<TMiCustomer> overTimeList = new ArrayList<>();
            //获取超时时间
            TSysDict dict = dictService.selectByPrimaryKey(HospitalOvertimeEnum.HOSPITAL_OVERTIME.getOvertimeId());
            if (dict != null) {
                for (TMiCustomer customer : customerList) {
                    LocalDateTime start = customer.getCreateTime();
                    LocalDateTime end = start.plusDays(Long.valueOf(dict.getDictValue()));
                    if (LocalDateTime.now().isBefore(end)) {
                        continue;
                    }
                    TMiCustomerUpgradeExample customerUpgradeExample = new TMiCustomerUpgradeExample();
                    TMiCustomerUpgradeExample.Criteria criteria = customerUpgradeExample.createCriteria();
                    criteria.andCustomerIdEqualTo(customer.getCustomerId());
                    criteria.andIsEnableEqualTo(CustomerStatusEnum.EFFECTIVE.getUpgradeStatus());
                    criteria.andUpgradeTypeEqualTo(UpgradeTypeEnum.UPGRADE_OPERATION.getUpgradeType());
                    criteria.andCreateTimeGreaterThanOrEqualTo(start);
                    criteria.andCreateTimeLessThanOrEqualTo(end);

                    if (customerUpgradeService.countByExample(customerUpgradeExample) <= 0) {
                        overTimeList.add(customer);
                    }
                }
            }
            pageInfo.setList(overTimeList);
        }


        //设置导出相关信息
        XSSFWorkbook wb = new XSSFWorkbook();

        XSSFSheet sheet = wb.createSheet("医院信息管理");
        List<TMiCustomer> customerResultList = pageInfo.getList();
        int rowIdx = 0;
        for (int p = 0; p < customerResultList.size(); p++) {

            TMiCustomer customer = customerResultList.get(p);

            String regionName = "";
            String areasCodeName = "";
            String agentName = "";
            //设置区域名称
            TMiRegionDetailExample regionDetailExample = new TMiRegionDetailExample();
            regionDetailExample.createCriteria().andAreasCodeEqualTo(customer.getAreasCode()).andRegionIdNotEqualTo(RegionEnum.NATIONAL_ADMINISTRATIVE_REGION.getId());

            List<String> regionIdList = regionDetailService.selectByExample(regionDetailExample).stream().map(TMiRegionDetail::getRegionId).collect(Collectors.toList());
            if (regionIdList != null && !regionIdList.isEmpty()) {
                TMiRegionExample regionExample = new TMiRegionExample();
                regionExample.createCriteria().andRegionIdIn(regionIdList);

                regionName = regionService.selectByExample(regionExample).stream().map(TMiRegion::getRegionName).collect(Collectors.joining(","));
            }
            //设置省级名称
            TSysAreas areas = areasService.selectByPrimaryKey(customer.getAreasCode());
            if (areas != null) {
                areasCodeName = areas.getName();
            }
            //设置代理商信息
            if ("0".equals(customer.getBelongTo())) {
                agentName = "总公司";
            } else {
                TMiCustomer tMiCustomer = customerService.selectByPrimaryKey(customer.getBelongTo());
                if (tMiCustomer != null) {
                    agentName = tMiCustomer.getCustomerName();
                }
            }


            //获取单个医院的联系人列表
            TMiCustomerContactsExample customerContactsExample = new TMiCustomerContactsExample();
            customerContactsExample.createCriteria().andCustomerIdEqualTo(customer.getCustomerId());

            List<TMiCustomerContacts> customerContactsList = customerContactsService.selectByExample(customerContactsExample);
            if (null == customerContactsList || customerContactsList.isEmpty()) {
                continue;
            }

            //获取单个医院的拜访记录
            TMiCustomerVisitExample customerVisitExample = new TMiCustomerVisitExample();
            customerVisitExample.createCriteria().andCustomerIdEqualTo(customer.getCustomerId());
            customerContactsExample.setOrderByClause("visit_date");

            List<TMiCustomerVisit> customerVisitList = customerVisitService.selectByExample(customerVisitExample);
            Map<String, List<TMiCustomerVisit>> customerVisitMap = new TreeMap<>(new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                    return o2.compareTo(o1);
                }
            });
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
            if (null != customerVisitList && !customerVisitList.isEmpty()) {
                for (TMiCustomerVisit customerVisit : customerVisitList) {
                    //获取拜访人名称
                    String visitName = "";
                    TSysAccount account = accountService.selectByPrimaryKey(customerVisit.getCreator());
                    if (account != null) {
                        visitName = account.getRealName();
                    }
                    String key = customerVisit.getVisitDate().format(formatter) + "--" + visitName;
                    List<TMiCustomerVisit> list;
                    if (customerVisitMap.containsKey(key)) {
                        list = customerVisitMap.get(key);
                    } else {
                        list = new ArrayList<>();
                    }
                    list.add(customerVisit);
                    customerVisitMap.put(key, list);
                }
            }

            sheet.setColumnWidth(0, (20 * 256));
            sheet.setColumnWidth(1, (20 * 256));
            sheet.setColumnWidth(2, (25 * 256));
            sheet.setColumnWidth(3, (25 * 256));
            for (int i = 0; i < customerVisitMap.size(); i++) {
                sheet.setColumnWidth(i + 4, (50 * 256));
            }

            XSSFRow row = sheet.createRow(rowIdx);
            row.setHeightInPoints(28);
            XSSFFont tableTitleFont = wb.createFont();
            tableTitleFont.setFontHeightInPoints((short) 12);
            tableTitleFont.setBold(true);
            XSSFCellStyle tableTitleStyle = wb.createCellStyle();
            tableTitleStyle.setFont(tableTitleFont);
            // 下边框
            tableTitleStyle.setBorderBottom(BorderStyle.THIN);
            // 左边框
            tableTitleStyle.setBorderLeft(BorderStyle.THIN);
            // 右边框
            tableTitleStyle.setBorderRight(BorderStyle.THIN);
            // 上边框
            tableTitleStyle.setBorderTop(BorderStyle.THIN);
            tableTitleStyle.setAlignment(HorizontalAlignment.CENTER);
            tableTitleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            createCell(row, 0, tableTitleStyle, "大区");
            createCell(row, 1, tableTitleStyle, "省份");
            createCell(row, 2, tableTitleStyle, "医院名称");
            createCell(row, 3, tableTitleStyle, customer.getCustomerName());
            createCell(row, 4, tableTitleStyle, " 代理商");
            createCell(row, 5, tableTitleStyle, agentName);
            createCell(row, 6, tableTitleStyle, " 项目医院分级");
            createCell(row, 7, tableTitleStyle, CustomerLevelTypeEnum.getHospitalDesc(customer.getLevel()));

            XSSFRow row0 = sheet.createRow(rowIdx + 1);
            row0.setHeightInPoints(28);

            XSSFFont tableHeaderFont = wb.createFont();
            tableHeaderFont.setFontHeightInPoints((short) 12);
            tableHeaderFont.setBold(true);
            XSSFCellStyle tableHeaderStyle = wb.createCellStyle();
            tableHeaderStyle.setFont(tableHeaderFont);
            // 下边框
            tableHeaderStyle.setBorderBottom(BorderStyle.THIN);
            // 左边框
            tableHeaderStyle.setBorderLeft(BorderStyle.THIN);
            // 右边框
            tableHeaderStyle.setBorderRight(BorderStyle.THIN);
            // 上边框
            tableHeaderStyle.setBorderTop(BorderStyle.THIN);
            tableHeaderStyle.setAlignment(HorizontalAlignment.CENTER);
            tableHeaderStyle.setVerticalAlignment(VerticalAlignment.CENTER);

            createCell(row0, 0, tableHeaderStyle, regionName);
            createCell(row0, 1, tableHeaderStyle, areasCodeName);
            createCell(row0, 2, tableHeaderStyle, "部门");
            createCell(row0, 3, tableHeaderStyle, "姓名");
            int index = 4;
            for (String key : customerVisitMap.keySet()) {
                createCell(row0, index, tableHeaderStyle, key);
                index++;
            }

            XSSFFont fontBody = wb.createFont();
            fontBody.setFontHeightInPoints((short) 11);
            XSSFCellStyle styleBody = wb.createCellStyle();
            styleBody.setFont(fontBody);
            // 下边框
            styleBody.setBorderBottom(BorderStyle.THIN);
            // 左边框
            styleBody.setBorderLeft(BorderStyle.THIN);
            // 右边框
            styleBody.setBorderRight(BorderStyle.THIN);
            // 上边框
            styleBody.setBorderTop(BorderStyle.THIN);
            styleBody.setAlignment(HorizontalAlignment.CENTER);
            styleBody.setVerticalAlignment(VerticalAlignment.CENTER);

            for (int i = 0; i < customerContactsList.size(); i++) {
                TMiCustomerContacts customerContacts = customerContactsList.get(i);
                String contactsId = customerContacts.getContactsId();

                XSSFRow trow = sheet.createRow(rowIdx + i + 2);
                trow.setHeightInPoints(24);
                createCell(trow, 0, styleBody, regionName);
                createCell(trow, 1, styleBody, areasCodeName);
                createCell(trow, 2, styleBody, customerContacts.getPost());
                createCell(trow, 3, styleBody, customerContacts.getContactsName());
                AtomicInteger idx = new AtomicInteger(4);
                customerVisitMap.forEach((key, value) -> {
                    StringBuilder stringBuilder = new StringBuilder();
                    for (TMiCustomerVisit customerVisit : value) {
                        if (contactsId.equals(customerVisit.getContactsId())) {
                            stringBuilder.append(customerVisit.getContent() + " ");
                        }
                    }
                    createCell(trow, idx.get(), styleBody, stringBuilder.toString());
                    idx.getAndIncrement();
                });
            }
            sheet.addMergedRegion(new CellRangeAddress(rowIdx + 1, rowIdx + customerContactsList.size() + 1, 0, 0));
            sheet.addMergedRegion(new CellRangeAddress(rowIdx + 1, rowIdx + customerContactsList.size() + 1, 1, 1));

            rowIdx += customerContactsList.size() + 3;
        }

        StringBuilder fileName = new StringBuilder();
        fileName.append("医院信息管理");

        fileName.append("_").append(System.currentTimeMillis());

        //创建临时文件
        File excelFile = File.createTempFile(fileName.toString(), ".xlsx");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        wb.write(baos);
        FileCopyUtils.copy(baos.toByteArray(), new FileOutputStream(excelFile));

        //保存到临时OSS上
        JsonResult<String> jsonResult = fileGenericStrategy.simpleFileUploadTempBucket("downloadExport", excelFile, fileName + ".xlsx");

        // 删除临时文件
        excelFile.delete();

        if (!jsonResult.getSuccess()) {
            throw new CustomException(jsonResult.getData().toString());
        }


        result.setData(jsonResult.getData());
        result.setMessage("OK");
        result.setStatus(HttpStatus.OK.value());


        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    /**
     * 创建单元格
     *
     * @param row
     * @param column
     * @param style
     * @param value
     */
    private void createCell(XSSFRow row, int column, XSSFCellStyle style, String value) {
        XSSFCell cell = row.createCell(column);
        cell.setCellValue(new XSSFRichTextString(value));
        cell.setCellStyle(style);
    }

    /***
     *  删除医院
     * @param customerId
     * @param request
     * @param response
     * @return
     */
    @OperLog(module = MODULE, action = OperLogActionEnum.DELETE, detail = "删除医院")
    @ApiOperation(value = "删除医院", notes = "删除医院")
    @ApiImplicitParam(dataType = "String", name = "customerId", value = "医院id")
    @DeleteMapping(value = "/delete")
    @RequiresPermissions("information:manage:hospital:delete")
    public ResponseEntity<HttpDataResult<Boolean>> delete(
            @RequestParam(value = "customerId") String customerId,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpDataResult<Boolean> result = new HttpDataResult<>(request.getRequestURI());


        if (null == customerId || "".equals(customerId.trim())) {
            throw new CheckException("需要删除的医院ID异常，删除操作失败！");
        }
        TMiCustomer customer = customerService.selectByPrimaryKey(customerId);
        if (customer == null) {
            throw new CheckException("需要删除的医院ID异常，删除操作失败！");
        }
        //等级大于1级，不允许删除
        if (customer.getLevel() > CustomerLevelTypeEnum.ONE.getType()) {
            throw new CheckException("医院等级大于A级，不允许删除！");
        }
        //跨月不能删除
        if (customer.getCreateTime().getMonthValue() != LocalDateTime.now().getMonthValue() || customer.getCreateTime().getYear() != LocalDateTime.now().getYear()) {
            throw new CheckException("无法删除跨月记录！");
        }
        //判断是否存在拜访记录
        TMiCustomerVisitExample customerVisitExample = new TMiCustomerVisitExample();
        customerVisitExample.createCriteria().andCustomerIdEqualTo(customerId);

        if (customerVisitService.countByExample(customerVisitExample) > 0) {
            throw new CheckException("已存在拜访记录，不允许删除！");
        }

        //删除客户表信息
        customerService.deleteByPrimaryKey(customerId);
        //删除联系人信息
        TMiCustomerContactsExample customerContactsExample = new TMiCustomerContactsExample();
        customerContactsExample.createCriteria().andCustomerIdEqualTo(customerId);

        customerContactsService.deleteByExample(customerContactsExample);
        //删除升降级记录信息
        TMiCustomerUpgradeExample customerUpgradeExample = new TMiCustomerUpgradeExample();
        customerUpgradeExample.createCriteria().andCustomerIdEqualTo(customerId);

        customerUpgradeService.deleteByExample(customerUpgradeExample);
        //删除所属权转移日志
        TMiCustomerTransferExample customerTransferExample = new TMiCustomerTransferExample();
        customerTransferExample.createCriteria().andCustomerIdEqualTo(customerId);

        customerTransferService.deleteByExample(customerTransferExample);

        result.setData(true);
        result.setMessage("OK");
        result.setStatus(HttpStatus.OK.value());
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

}